no-commit-to-branch: Auto-detect repository's default branch#1245
no-commit-to-branch: Auto-detect repository's default branch#1245emanb29 wants to merge 2 commits intopre-commit:mainfrom
Conversation
| Both `main` and `master` are protected by default if no branch argument is set. | ||
| If no branch argument is set, the hook auto-detects the repository's default | ||
| branch from `origin/HEAD`. Falls back to protecting both `main` and `master` | ||
| if `origin/HEAD` is not configured. |
There was a problem hiding this comment.
as written this is a breaking change
please in the future discuss feature ideas before wasting time on implementation such that we can find the problems during the design phase rather than at the last mile of the coding phase
I suspect if this is going to be accepted at all this would need to be a separate option rather than an implicit behaviour -- especially because as written it is an inconsistent implicit behaviour (based on the repository state)
and with a required option to trigger this behaviour -- I kinda see little point to the option at all (since you could just specify the option that's already there with the proper value instead and accomplish the same thing)
There was a problem hiding this comment.
It's theoretically a breaking change, but not practically. I suspect anyone relying on the default is doing so because of an intent to protect their trunk branch.
As for the process quibble: the greater waste would have been a discussion -- I needed this behavior, now I have a fork with it. An unexpected 9-line PR isn't dropping a huge amount of work on you and other maintainers without any notice, so I decided to offer it to the community for a tool I've found generally delightful to use rather than keeping it in an isolated fork.
You're welcome to take the change, reject it, or modify it to your liking. Consider this PR a notice of interest from a community member and an offer to save you some work in the case your philosophy as a maintainer aligns with mine as a user.
Many repos I work on use
devordevelopfor the trunk branch -- it'd be convenient for those to be protected as defaults. However, others may well usedevas an intentionally-volatile branch. Instead of guessing, we can infer the default branch by inspectingorigin/HEAD. If that fails for whatever reason, fall back to the previous default ofmaster+main